String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.trimLeft = function() { return this.replace(/(^\s*)/g, ""); } 
String.prototype.trimRight = function() { return this.replace(/(\s*$)/g, ""); }
String.prototype.replaceAll = function(s1,s2){if(s1==undefined){s1=" ";}if(s2==undefined){s2="";}return this.replace(new RegExp(s1,"gm"),s2); }
function toJson(jsonString,call){try{return eval('('+jsonString+')');}catch(e){if(call != undefined){call(e);}else{alert("Json Format Transfer Error:"+e.message);throw e;}}}
function closeWindow(){try{window.close();}catch(e){log(e.message);};try{self.opener = null;self.open('','_self');self.close();}catch(e){}}
function log(txt){try{if(console){console.log(txt);}}catch(e){}}
function es(id,tag){var obj=id;if(typeof(id)=="string"){obj=get(id);};return obj.getElementsByTagName(tag);}
function hidden(id){try{var obj=document.getElementById(id);if(obj!=undefined){obj.style.display="none";};return obj;}catch(e){log("hidden error "+id);}}
function show(id){try{var obj=document.getElementById(id);if(obj!=undefined){obj.style.display="";};return obj;}catch(e){log("show error "+id);}}
function get(id,html)
{
   	var ele=document.getElementById(id);
   	try{
   		if((ele != undefined)&&(html != undefined)){var tagName=ele.tagName.toLowerCase();if(("input" == tagName)||("textarea" == tagName)){ele.value=html;}else{ele.innerHTML=html;}}
   	}catch(e){}
   	return ele;
}
function toMap(strs)
{
	var arr=strs.split("&");
	var param=new Object();
	for(var i=0;i<arr.length;i++)
	{
		var item=arr[i];
		param[item.split("=")[0]]=item.substring(item.indexOf("=")+1);
	}
	return param;
}
function toParam(strs){return toMap(strs);}

function ajax(object)
{
	try
	{
		var xmlhttp;
		if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}// code for IE7+, Firefox, Chrome, Opera, Safari 
		else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}// code for IE6, IE5
		xmlhttp.open("post",object.url,true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
		var params="";
		if(object.params != undefined ){params=object.params;}
		if(object.param != undefined ){params=object.param;}
		xmlhttp.send(params); 
		xmlhttp.onreadystatechange=function()
		{
			if(typeof(object.change)=="function"){object.change(xmlhttp.readyState,xmlhttp.status,xmlhttp.statusText);}
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
						var result=xmlhttp.responseText+"";
						var call=object.success;
						if(call != undefined )
						{
							if(typeof(call)=="function") 
							{
								object.map=toMap(object.params);
								call(result,object);
							}
							else if(typeof(call)=="object"){call.innerHTML=result;}
							else if(get(call+""))
							{
								get(call+"").innerHTML=result;
							}
						}
			}
		}
	}catch(e)
	{
		log("error "+e.message);
		if(typeof(object.error)=="function" )
		{ 
			object.map=toMap(object.params);
			object.error(e,object);
		}
	}
}

